#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
using namespace std;
struct stu{
	string weight;
	char hat[10];
};
bool cmp(stu x, stu y){
	return x.weight<y.weight;
}

int main(){
	stu ss[100];
	int a;
	cin>>a;
	for(int i=0;i<a;i++){
		cin>>ss[i].weight>>ss[i].hat;
	}
	sort(ss,ss+a,cmp);
	for(int i=0;i<a;i++){
		cout<<ss[i].hat<<endl;
	}
	return 0;
}
